<?php
header("Content-type:text/html;charset=utf-8"); 
include 'conn.php';
include 'func.php';
include 'phpwindfunc.php';
define('ERR_DB',"<META http-equiv=Content-Type content=\"text/html; charset=utf-8\">数据库链接失败！".mysql_error());
for($i=0;$i<3;$i++){
	$cfg_link = mysql_connect($dbserver, $dbuser, $dbpass);
	if($cfg_link){break;}
	sleep(1);
}
if(!$cfg_link){echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />".ERR_DB."</meta>";exit;}
mysql_select_db($dbname);
mysql_query("set names utf8");

function set_constants($table) {
	global $BIAOTOU;
	$data = array ();
	$sql = "show fields from " . $BIAOTOU . $table; //得到全表信息
	$query = mysql_query($sql);
	while ($row = mysql_fetch_array($query)) {
		$data[] = str_replace('_', '', strtoupper($row['Field']));
	}

	$data = array_diff($data, array (
		'ID'
	));

	$sql = "select * from " . $BIAOTOU .$table." where Id=1";
	$query = mysql_query($sql);
	$i = 1;
	$set = mysql_fetch_array($query, MYSQL_NUM);

	for ($i = 1; $i < count($set); $i++) {
		define($data[$i], $set[$i]);
	}
}

$cfg_sql2="select * from ".$BIAOTOU."taobaoset where Id=1";
$cfg_rs2 = mysql_query($cfg_sql2);
while ($cfg_row2 = mysql_fetch_array($cfg_rs2)){
	define('MYAPPKEY',passport_decrypt($cfg_row2["appKey"],$cfg_row2["seckey"]));
	define('MYUSERNICK',urldecode(passport_decrypt($cfg_row2["usernick"],$cfg_row2["seckey"])));
	define('MYAPPSECRET',$cfg_row2["appSecret"]);
	define('MYUSERPID',$cfg_row2["userpid"]);
	define('APPKEY2',$cfg_row2["appkey2"]);
	define('APPKEY3',$cfg_row2["appkey3"]);
	define('APPKEY4',$cfg_row2["appkey4"]);
	define('APPKEY5',$cfg_row2["appkey5"]);
	define('APPSECRET2',$cfg_row2["appsecret2"]);
	define('APPSECRET3',$cfg_row2["appsecret3"]);
	define('APPSECRET4',$cfg_row2["appsecret4"]);
	define('APPSECRET5',$cfg_row2["appsecret5"]);
	define('APPNUM',$cfg_row2["appnum"]);
	define('APPNUM2',$cfg_row2["appnum2"]);
	define('APPNUM3',$cfg_row2["appnum3"]);
	define('APPNUM4',$cfg_row2["appnum4"]);
	define('APPNUM5',$cfg_row2["appnum5"]);
	define('SESSIONKEY',$cfg_row2["sessionkey"]);
	define('SESSIONTIME',$cfg_row2["sessiontime"]);
	define('GETKEY',$cfg_row2["getkey"]);
	define('CHKEY',$cfg_row2["chkey"]);
}

set_constants('websetting');

	 if(WEBCLOSE==1&&$isadmin!=1){
	 	echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><title>".WEBTITLE."网站关闭提示</title><table width=\"550\" height=\"176\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" style=\"border:1px dotted #ddd\"><tr><td colspan=\"2\" align=\"center\"><img src=\"images/alert.gif\" width=\"100\" height=\"90\" /></td><td width=\"370\" style=\"font-size:25px; font-weight:bold;\">".WEBCLOSEMSG."</td></tr></table><table width=\"550\" height=\"25\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\"><tr><td colspan=\"3\" align=\"right\">- by ".WEBTITLE."</td></tr></table>";
		exit;
	}


$cfg_sql3="select * from ".$BIAOTOU."apireg where id=1";
$cfg_rs3 = mysql_query($cfg_sql3);
while ($cfg_row3 = mysql_fetch_array($cfg_rs3)){
define('APIREG',$cfg_row3["apireg"]);
/**
@淘宝API参数设置
*/	
define('TAOAPPKEY',$cfg_row3["taoappKey"]);
define('TAOAPPSECRET',$cfg_row3["taoappSecret"]);
define('TAOAPPON',$cfg_row3["taoappon"]);

/**
@支付宝API参数设置
*/
define( "ALIPAY_PID" , $cfg_row3["alipayappKey"] );//app key
define( "ALIPAY_KEY" , $cfg_row3["alipayappSecret"] );//app secret
define( "ALIPAY_RETURN" , 'http://'.URL.'/api/alipay/return_url.php' );//回调URL
define('ALIPAYAPPON',$cfg_row3["alipayappon"]);
	 
/**
@腾讯微博API参数设置
*/
define( "QQWB_AKEY" , $cfg_row3["qqappKey"] );//app key
define( "QQWB_SKEY" , $cfg_row3["qqappSecret"] );//app secret
define( "QQWB_RequestToken" , 'http://'.URL.'/api/qqweibo/callback.php' );//回调URL
define('QQAPPON',$cfg_row3["qqappon"]);

/**
@QQ空间API参数设置
*/
define( "QQLOGIN_AKEY" , $cfg_row3["qqlappKey"] );//app key
define( "QQLOGIN_SKEY" , $cfg_row3["qqlappSecret"] );//app secret
define( "QQLOGIN_RequestToken" , 'http://'.URL.'/api/qqspace/oauth/get_access_token.php' );//回调URL
define('QQLAPPON',$cfg_row3["qqlappon"]);

/**
@新浪微博API参数设置
*/
define( "SWB_AKEY" , $cfg_row3["sinaappKey"] );//app key
define( "SWB_SKEY" , $cfg_row3["sinaappSecret"] );//app secret
define( "SWB_RequestToken" , 'http://'.URL.'/api/sina/callback.php' );//回调URL
define('SINAAPPON',$cfg_row3["sinaappon"]);
/**
@开心网API参数设置
*/
define( "KAIXIN_AKEY" , $cfg_row3["kaixinappKey"] );//app key
define( "KAIXIN_SKEY" , $cfg_row3["kaixinappSecret"] );//app secret
define( "KAIXIN_RequestToken" , 'http://'.URL.'/api/kaixin/callback.php' );//回调URL
define('KAIXINAPPON',$cfg_row3["kaixinappon"]);
}

define('DDROOTPATH',dirname(dirname(__FILE__)));

define('ERR404',"<HTML><HEAD><META http-equiv=Content-Type content=\"text/html; charset=utf-8\"><TITLE>".WEBTITLE."提醒您：您访问的页面不存在 请转到首页进入</TITLE><STYLE type=text/css></STYLE><LINK type=text/css rel=stylesheet><STYLE type=text/css>BODY{FONT-SIZE: 9pt; COLOR: #842b00; LINE-HEIGHT: 16pt; FONT-FAMILY: \"Tahoma\", \"宋体\"; TEXT-DECORATION: none}TABLE{FONT-SIZE: 9pt; COLOR: #842b00; LINE-HEIGHT: 16pt; FONT-FAMILY: \"Tahoma\", \"宋体\"; TEXT-DECORATION: none
}TD{FONT-SIZE: 9pt; COLOR: #842b00; LINE-HEIGHT: 16pt; FONT-FAMILY: \"Tahoma\", \"宋体\"; TEXT-DECORATION: none
}BODY{SCROLLBAR-HIGHLIGHT-COLOR: buttonface; SCROLLBAR-SHADOW-COLOR: buttonface; SCROLLBAR-3DLIGHT-COLOR: buttonhighlight; SCROLLBAR-TRACK-COLOR: #eeeeee; BACKGROUND-COLOR: #ffffff}A{FONT-SIZE: 9pt; COLOR: #842b00; LINE-HEIGHT: 16pt; FONT-FAMILY: \"Tahoma\", \"宋体\"; TEXT-DECORATION: none}A:hover{FONT-SIZE: 9pt; COLOR: #0188d2; LINE-HEIGHT: 16pt; FONT-FAMILY: \"Tahoma\", \"宋体\"; TEXT-DECORATION: underline}H1{FONT-SIZE: 9pt; FONT-FAMILY: \"Tahoma\", \"宋体\"}</STYLE><META content=\"MSHTML 6.00.2800.1458\" name=GENERATOR></HEAD><BODY topMargin=20><TABLE cellSpacing=0 width=600 align=center border=0 cepadding=\"0\">
<TBODY><TR colspan=\"2\"><TD><!--------System Return Begin------------><H1>无法找到该页</H1>HTTP 错误 404：您正在搜索的页面可能已经删除、更名或暂时不可用。<HR noShade SIZE=0><P>☉ 请尝试以下操作：</P><UL><LI>确保浏览器的地址栏中显示的网站地址的拼写和格式正确无误。 <LI>如果通过单击链接而到达了该网页，请与网站管理员联系，通知他们该链接的格式不正确。 <LI>单击<A href=\"javascript:history.back(1)\"><FONT color=#ff0000>后退</FONT></A>按钮尝试另一个链接。 </LI></UL><P>☉ ".URL."  ".WEBTITLE."欢迎您再次到来：<UL><LI><A href=\"http://".URL."/\" target=_blank>http://".URL."</A></LI></UL><HR noShade SIZE=0><P>☉ 如果您对本站有任何疑问、意见、建议、咨询，请联系管理员QQ:".QQ."</A><BR>&nbsp;&nbsp;&nbsp;<BR></P><!------------End this!---------------></TD></TR></TBODY></TABLE></BODY></HTML>");
define('ERR403',"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><HTML><HEAD><META http-equiv=Content-Type content=\"text/html; charset=utf-8\"><TITLE>".WEBTITLE."提醒您：您访问的页面暂时无法打开，请重新搜索试试</TITLE></head><body><div style=\"width:950px; height:400px; line-height:150px; text-align:center; font-size:14px; color:#d00; margin:20px auto;\">您请求的页面暂时无法打开或者该商品可能已经下架，请再次搜索下试试！<script type='text/javascript'>alimama_pid='mm_".MYUSERPID."_0_0';alimama_type='g';alimama_tks={};alimama_tks.style_i=1;alimama_tks.lg_i=1;alimama_tks.w_i=572;alimama_tks.h_i=69;alimama_tks.btn_i=1;alimama_tks.txt_s='';alimama_tks.hot_i=1;alimama_tks.hc_c='#0065FF';alimama_tks.c_i=1;alimama_tks.cid_i=0;</script><script type='text/javascript' src='http://a.alimama.cn/inf.js'></script></div></body></html>");

$sql = "show processlist";
$query = mysql_query($sql);
while($r = mysql_fetch_array($query)){
	if($r["Command"]=="Sleep" && $r['Time']>5){
		mysql_query("kill ".$r["Id"]);
	}
}
?>